# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=nftables
pkgver=1.0.4
pkgrel=0
pkgdesc="Netfilter tables userspace tools"
url="https://netfilter.org/projects/nftables"
arch="all"
license="GPL-2.0-or-later"
makedepends="
	automake
	autoconf
	libtool
	asciidoc
	bison
	docbook2x
	flex
	gmp-dev
	jansson-dev
	libmnl-dev
	libnftnl-dev
	ncurses-dev
	readline-dev
	"
install="$pkgname.post-upgrade"
subpackages="$pkgname-static $pkgname-dev $pkgname-doc $pkgname-openrc"
source="https://netfilter.org/projects/nftables/files/nftables-$pkgver.tar.bz2
	nftables.confd
	nftables.initd
	nftables.nft
	"
builddir="$srcdir/$pkgname-$pkgver"

prepare() {
	default_prepare
	sed -i '1i#include "config.h"' "$builddir"/src/proto.c
	autoreconf -fi
	rm -Rf autom4te*.cache config.h.in~
}

build() {
	CONFIG_MAN=y DB2MAN=docbook2x-man ./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/usr/share \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--enable-static=yes \
		--with-json \
		--with-cli=readline
	make
}

package() {
	make DESTDIR="$pkgdir" install

	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	install -Dm644 "$srcdir"/nftables.nft "$pkgdir"/etc/nftables.nft
	install -dm755 "$pkgdir"/etc/nftables.d
}

sha512sums="
7d96c791365d399b3b930a1f9d6c6aa4a8c2180c258bb5163d9d62ea4d094857e2ebb20fc3ef13b89f449f216d0a291d3bcf288704f1e3bd3ceb51b6cadf8215  nftables-1.0.4.tar.bz2
cca875473bbd7b2326afcaeec84b1f9826afb70fc67381a64f3ad104a13a314bd2c352e0fac1f602b9980edb2818bf6242373aa1634ce17bcc1d82eeb8b05b39  nftables.confd
739e704b263b7afd124c5f497fef43c6f5de69f0a75e0a370c2b84f84619ca6a8a64fe704413c2d1cc1e4a0db062cce2c7fb807c202f9a1a1f60152bd45ad914  nftables.initd
8770185348e98c3fb7fb3106441bb89f31f9157f8fd475a238ea91f288f4babee7d867b229c5bb29fabca6fce6f3679f9f9c17fdbc077e3693d7c00ee2611446  nftables.nft
"
